﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    class TemplateListConverter : IMultiValueConverter
    {

        //#region IValueConverter 成员

        //public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        //{
        //    ObservableCollection<ITemplateToLoadViewModel> list = value as ObservableCollection<ITemplateToLoadViewModel>;
        //    if (list != null)
        //    {
        //        var tt = list.OrderBy(p => p.Name);
        //        return tt;
        //    }
        //    else
        //    {
        //        return value;
        //    }
        //}

        //public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        //{
        //    throw new NotImplementedException();
        //}

        //#endregion
        #region IMultiValueConverter 成员

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection<ITemplateToLoadViewModel> list = values[0] as ObservableCollection<ITemplateToLoadViewModel>;
            string groupName = values[1] as string;
            if (list != null)
            {
                if (groupName != null && groupName == UILanguage.TryFindResource("Template_NotGrouped"))
                {
                    var tt = list.Where(p => !p.Name.Contains("-"));
                    return tt;
                }
                else if (groupName != null && groupName != UILanguage.TryFindResource("Template_All"))
                {
                    var tt = list.Where(p => p.Name.StartsWith(groupName));
                    return tt;
                }
                else
                {
                    return list;
                }
            }
            else
            {
                return null;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
